package com.qualiti.javaweb.conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;

import com.qualiti.javaweb.mb.BancoDeDados;
import com.qualiti.javaweb.modelo.Autor;

@FacesConverter(value="converterAutor")
public class ConverterAutor implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
			throws ConverterException {
		return BancoDeDados.obterAutorPorNome(arg2);
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
			throws ConverterException {
		if (arg2 == null) {
			return null;
		}
		return ((Autor) arg2).getNome();
	}
}
